package org.atlantis.grosbeak.depot.proxy.value;

import org.atlantis.grosbeak.depot.DepotMaker;
import org.atlantis.grosbeak.depot.DepotUtils;
import org.atlantis.grosbeak.depot.proxy.ValueProxy;
import org.atlantis.grosbeak.lang.Pair;

/**
 * 引用值的代理。在配置文件中的格式应该是：“refer : 'Boy'”，那么获取的应该是ID为Boy的对象。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
public class ReferValueProxy implements ValueProxy {

	private String id;
	private Class<?> type;

	public ReferValueProxy(String name) {
		Pair<Class<?>> pair = DepotUtils.parseName(name);
		this.id = pair.getKey();
		this.type = pair.getValue();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.atlantis.grosbeak.depot.proxy.ValueProxy#get(org.atlantis.grosbeak
	 * .depot.DepotMaker)
	 */
	public Object get(DepotMaker maker) {
		return maker.getDepot().get(type, id);
	}
}
